import {Component, ViewChild} from "@angular/core";
import {Router} from "@angular/router";
import {Award} from "../svrs/domain";
import {AwardService} from "../svrs/award.service";
import {DialogComponent, DialogConfig, DialogService, InfiniteLoaderComponent, InfiniteLoaderConfig} from "ngx-weui";


@Component({
  selector: 'zm-award',
  templateUrl: './award.component.html',
  styleUrls: ['./award.component.css']
})
export class AwardComponent {
  @ViewChild('auto') autoASS: DialogComponent;
  @ViewChild('ios') autoAS;

  @ViewChild(InfiniteLoaderComponent) il;
  restartBtn = false;
  awards:Award[];
  config: DialogConfig={
    /**
     * 对话框类型，默认：`default`
     * default：默认文本或HTML格式
     * prompt：可输入对话框
     */
    type: 'default',

  /**
   * 标题
   */
  title: 'dialog excess',
  /**
   * 内容（支持HTML）
   */
  content: 'custom param',

  };
  configios={
    type:'prompt',
    title:'www'
  }
  infiniteConfig = {
    height:"70vh",
  /**
   * 加载中文本（支持HTML），默认：weui-loadmore 组件
   */
  loading: 'loading more extent',
  /**
   * 完成所有数据加载文本（支持HTML），默认：weui-loadmore 组件
   */
  finished: '没有了没有了'
}
constructor(private route:Router,private svr:AwardService,private dialogSvr: DialogService){
  this.svr.getawards().subscribe(
    (data)=>{
      this.awards=data;
    }
  )
}

    dialogShow() {
    this.autoASS.show().subscribe(res => {
      console.log(res);
    })
    }
    dialogShow1(){
    this.autoAS.show().subscribe(ress=>{console.log(ress)})
    }

    dialogSvrShow(){
    let config = this.config;
    config.type = 'prompt';
    this.dialogSvr.show(config).subscribe(res=>{
      console.log(res);
    });
    }

    onLoadMore(cn: InfiniteLoaderComponent) {
      this.svr.getawards().subscribe(
        (data)=>{
          if (this.awards.length >= 40){
            cn.setFinished();
                return;
          } else {
            this.awards.push(...data);
            cn.resolveLoading();
            this.restartBtn =true;
          }
        }
      )
    }
  res() {
    this.awards.length = 0;
    this.il.restart();
  }

//   nav(){
// this.route.navigateByUrl("1")
//   }
//   nav1(){
//     this.route.navigateByUrl("2")
//   }
//   nav2(){
//     this.route.navigateByUrl("3")
//   }
}
